package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mapper.RolePrivilegeMapper;
import com.example.pojo.RolePrivilege;
import com.example.service.RolePrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-08-20
 */
@Service
public class RolePrivilegeServiceImpl extends ServiceImpl<RolePrivilegeMapper, RolePrivilege> implements RolePrivilegeService {
    @Autowired
    private RolePrivilegeMapper rolePrivilegeMapper;

    @Override
    public void savePrivilege(Integer rid, Integer[] pids) {
        //先删除已有权限
        LambdaQueryWrapper<RolePrivilege> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(rid != null, RolePrivilege::getRid, rid);
        this.remove(wrapper);
        //添加新的权限信息
        for (Integer pid : pids) {
            rolePrivilegeMapper.savePrivilege(rid, pid);
        }

    }
}
